/**
 * 1824. 最少侧跳次数
 * @param {number[]} obstacles
 * @return {number}
 */
// dp + 滚动数组
var minSideJumps = function (obstacles) {
	const n = obstacles.length - 1
	// 青蛙可以从当前位置跳到上一个跑道和下一个跑到
	const d = [1, 0, 1]
	for (let i = 1; i <= n; i++) {
		let minCnt = Number.MAX_VALUE
		for (let j = 0; j < 3; j++) {
			if (j === obstacles[i] - 1) {
				d[j] = Number.MAX_VALUE
			} else {
				minCnt = Math.min(minCnt, d[j])
			}
		}
		for (let j = 0; j < 3; j++) {
			if (j === obstacles[i] - 1) continue
			d[j] = Math.min(d[j], minCnt + 1)
		}
	}
	return Math.min(...d)
}
const res = minSideJumps([0, 2, 1, 0, 3, 0])
console.log('minSideJumps :>>', res)
